<?php

/**
 * ProductPhoto form.
 *
 * @package    tsantek-shop
 * @subpackage form
 * @author     Tomislav Šantek
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ProductPhotoForm extends BaseProductPhotoForm
{
    public function configure()
    {
            $this->useFields(array('picture', 'caption', 'order_num'));

            $this->setWidget('order_num', new sfWidgetFormInputHidden());

            $this->setWidget('picture', new sfWidgetFormInputFileEditable(array(
                    'file_src'    => '/uploads/product/'.$this->getObject()->picture,
                    'edit_mode'   => !$this->isNew(),
                    'is_image'    => true,
                    'with_delete' => false,
              )));

            $this->setValidator('picture', new sfValidatorFile(array(
                            'mime_types' => 'web_images',
                            'path' => sfConfig::get('sf_upload_dir') . '/product',
                            'required' => false,
                    )));

            $this->validatorSchema['caption']->setOption('required', false);
    }

    public function generatePictureFilename()
    {
            $pic_name = Doctrine_Inflector::urlize($this->getObject()->getProduct()->getName());
            return $pic_name.'-'.uniqid().'.jpg';
    }
}
